package com.hdjk.view.callback;

import com.hdjk.view.entity.PerformanceEntity;
import com.lst.projectlib.entity.Msg;

import org.json.JSONObject;

import java.math.BigDecimal;

import okhttp3.Response;

/**
 * Created by sxy on 2017/11/2.
 */

public abstract class GetPerformanceCallBack extends MsgCallBack {
    @Override
    public Msg parseNetworkResponse(Response response, int i) throws Exception {
        Msg msg = super.parseNetworkResponse(response, i);
        JSONObject object = (JSONObject) msg.getData();
        if (object!=null) {
            PerformanceEntity entity = new PerformanceEntity();
            if (!object.isNull("day1")) {
                double l = object.getDouble("day1");
                BigDecimal b = new BigDecimal(l);
                entity.setDay1(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
            }
            if (!object.isNull("month1")) {
                double l = object.getDouble("month1");
                BigDecimal b = new BigDecimal(l);
                entity.setMonth1(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
            }
            if (!object.isNull("month3")) {
                double l = object.getDouble("month3");
                BigDecimal b = new BigDecimal(l);
                entity.setMonth3(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
            }
            if (!object.isNull("month6")) {
                double l = object.getDouble("month6");
                BigDecimal b = new BigDecimal(l);
                entity.setMonth6(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
            }
            if (!object.isNull("sinceLaunch")) {
                double l = object.getDouble("sinceLaunch");
                BigDecimal b = new BigDecimal(l);
                entity.setSinceLaunch(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
            }
            if (!object.isNull("week1")) {
                double l = object.getDouble("week1");
                BigDecimal b = new BigDecimal(l);
                entity.setWeek1(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
            }
            if (!object.isNull("year1")) {
                double l = object.getDouble("year1");
                BigDecimal b = new BigDecimal(l);
                entity.setYear1(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
            }
            if (!object.isNull("year2")) {
                double l = object.getDouble("year2");
                BigDecimal b = new BigDecimal(l);
                entity.setYear2(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
            }
            if (!object.isNull("year3")) {
                double l = object.getDouble("year3");
                BigDecimal b = new BigDecimal(l);
                entity.setYear3(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
            }
            if (!object.isNull("yearToDate")) {
                double l = object.getDouble("yearToDate");
                BigDecimal b = new BigDecimal(l);
                entity.setYearToDate(b.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
            }
            msg.setData(entity);
        }
        return msg;
    }
}
